<?php

// +----------------------------------------------------------------------
// | ????"
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2030 http://www.jmzh1688.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: lxl
// +----------------------------------------------------------------------


namespace app\admin\controller;

use think\Controller;
use think\Db;

use app\admin\model\SysMenuModel;


class Sysmenu extends Base
{


    public function board()
    {
        return $this->fetch();
    }





    public function index()
    {

      
        return $this->fetch();

    }

 


    
    public function del()
    {
        $menumodule = new SysMenuModel();
        if(request()->isPost()){
            $id = input("post.id");
            $msg = $menumodule->delById($id);
            return json(msg($msg['code'], $msg['data'], $msg['msg']));
        }
        return $this->fetch();
    }



    
    public function edit()
    {
        $menumodule = new SysMenuModel();

        if(request()->isPost()){
            $param = input("post.");
            $msg = $menumodule->edit($param);
            return json(msg($msg['code'], $msg['data'], $msg['msg']));
        }
      
        $id = input('param.id');
        $menu=$menumodule->getById($id);
        $menulist=doListMenu($menumodule->getListbyRoleId(0));

        $this->assign([
            'menulist' => $menulist,
            'menu' => $menu
        ]);
        return $this->fetch();
    }


    public function add()
    {
        $menumodule = new SysMenuModel();

        if(request()->isPost()){
            $param = input("post.");
            $msg = $menumodule->add($param);
            return json(msg($msg['code'], $msg['data'], $msg['msg']));
        }
      

        $menulist=doListMenu($menumodule->getListbyRoleId(0));
        $parentid = input('param.parentid');
        $this->assign([
            'menulist' => $menulist,
            'parentid' => $parentid,
        ]);
        return $this->fetch();
    }


    /**
     * 获取接口，二级菜单
     */
    public function jsonlist()
    {

        $menmodule=new SysMenuModel();

        $menulist=doListMenu($menmodule->getListbyRoleId(0));
        echo json_encode($menulist);
    }

    /**********************************LAYUI 基础版本修改 开始***********************************/
    /**
     * 获取菜单数据列表
     * @return mixed
     */
    public function ajaxGetSysmenu(){
        $menmodule = new SysMenuModel();
        $menulist=doListMenu($menmodule->getListbyRoleId(0));

        if($menulist){
            $ret['data'] = $menulist;
            $ret['code'] = 0;
            $ret['msg']  = '获取数据成功';
        }else{
            $ret['data'] = '';
            $ret['code'] = -1;
            $ret['msg']  = '获取数据为空';
        }

        return $ret;
    }

    /**
     * <layui 改版> 保存数据
     * @return array
     */
    public function ajaxSaveData(){
        $model = new SysMenuModel();
        if(request()->isAjax()){
            $param = input("post.");

            if($param['type']=='add'){
                unset($param['type']);
                $result = $model->add($param);
                return $result;
            }
            if($param['type']=='edit'){
                unset($param['type']);

                if(!isset($param['showstatus'])){
                    $param['showstatus']=1;
                }
                $result = $model->edit($param);
                return $result;
            }
            if($param['type']=='del'){
                $id = $param['id'];
                $result = $model->delById($id);
                return $result;
            }

        }
    }
}
